package com.heu.blood.match.dao;

import com.heu.blood.match.entity.BloodInformationEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.heu.blood.statistic.entity.BloodStoreCountABO;
import com.heu.blood.statistic.entity.BloodStoreCountType;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 
 * 
 * @author lyj
 * @email lyj@heu.com
 * @date 2023-06-16 00:23:13
 */
@Repository
@Mapper
public interface BloodInformationDao extends BaseMapper<BloodInformationEntity> {
    //批量导入血液库存信息
    Integer batchImportBloodInformationInfo(List<Map> bloodInformationList);



    //@Param("ew") Wrapper<BloodOutStorgeEntityVo> wrapper
    @Select("select u.dict_value as bloodTypeName,o.blood_type as bloodTypeCode,count(*) as bloodTypeCount from blood_information as o left join dict_data as u on o.blood_type = u.dict_code where o.blood_state = \"IN_STOCK\" and o.is_deleted = 0 and o.if_show = 1 GROUP BY o.blood_type")
    //查询库存血液按类型统计
    List<BloodStoreCountType> selectBloodTypeCount();

    @Select("select o.abo_blood_type as AboType , o.rh_blood_type as RhType,count(*) as AboCount from blood_information as o WHERE o.if_show = 1 and o.is_deleted = 0 and o.blood_state = \"IN_STOCK\" GROUP BY o.abo_blood_type,o.rh_blood_type")
    List<BloodStoreCountABO> selectAboTypeCount();

    //更新为在库状态
    void batchUpdateStateForInStockByBloodId(@Param("bloodids") List<String> bloodids ,String bloodState);

    //更新为退血状态，此状态需要删除血液
    void batchUpdateStateForReturnByBloodId(@Param("bloodids") List<String> bloodids ,String bloodState);


}
